package org.chen.newsapi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.chen.newsapi.dto.UserArticleQueryParam;
import org.chen.newsapi.entity.Article;

import java.util.List;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {
    
    IPage<Article> selectArticlesByCondition(
            Page<Article> page, 
            @Param("param") UserArticleQueryParam param
    );
    
    @Select("SELECT * FROM articles WHERE category = #{category} AND id != #{excludeId} ORDER BY view_count DESC LIMIT 5")
    List<Article> selectRelatedArticles(@Param("category") String category, @Param("excludeId") String excludeId);
}